package com.diyunapp.xilinapp.selfdefine;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.diyunapp.xilinapp.R;

import java.lang.reflect.Field;

public class StatusBarFragmentActivity extends FragmentActivity {
	//状态栏高度
	int  sbar = 0;
	Class<?> c = null;
	Object obj = null;
	Field field = null;
	int x = 0;
	
	private TextView menu_title_tv;
	private ImageButton menu_back_bt;
	private ImageButton menu_menu_bt;
	private View statusbar_view;
	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		try 
        {
    	    c = Class.forName("com.android.internal.R$dimen");
    	    obj = c.newInstance();
    	    field = c.getField("status_bar_height");
    	    x = Integer.parseInt(field.get(obj).toString());
    	    sbar = getResources().getDimensionPixelSize(x);
    	}
        catch(Exception e1)
    	{
    	    e1.printStackTrace();
    	}

		if (android.os.Build.VERSION.SDK_INT > 18)
		{
			Log.i("zhangxiaoxidebug","StatusBarFragmentActivity = "+android.os.Build.VERSION.SDK_INT );
			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

			/*window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
							WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);*/
			// 创建状态栏的管理实例
			SystemBarTintManager tintManager = new SystemBarTintManager(this);
			// 激活状态栏设置
			tintManager.setStatusBarTintEnabled(true);
			// 激活导航栏设置  华为手机的虚拟键盘功能与此功能设置有冲突，故不使用对底部导航栏的自定义功能
			//tintManager.setNavigationBarTintEnabled(true);
			// 设置一个颜色给系统栏
			tintManager.setTintColor(getResources().getColor(R.color.domain_orange));
		}
	}

	protected void MenuWidget(View myView)
	{
		//解决状态栏占空的问题
		if (android.os.Build.VERSION.SDK_INT > 18)
		{
			statusbar_view = myView.findViewById(R.id.actionbar_status_bar);
			statusbar_view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,sbar));
			statusbar_view.setVisibility(View.VISIBLE);
		}
	}

	public void toast(String msg){
		Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
	}
}
